package com.Servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.text.DecimalFormat;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jdbc.Jdbc;

/**
 * Servlet implementation class updatesales
 */
@WebServlet("/updatesales")
public class updatesales extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public updatesales() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
				request.setCharacterEncoding("utf-8");
				String id = request.getParameter("id");
				
				
				
				
				
				
				//流水号部分结束
				String cname = request.getParameter("chinesename");
				String ename = request.getParameter("englishname");
				String sex = request.getParameter("sex");
				String birthday = request.getParameter("birthday");
				String messagefrom = request.getParameter("messagefrom");
				String marketman = request.getParameter("marketman");
				String counselor = request.getParameter("counselor");
				String pcounselor = request.getParameter("phonecounselor");
				String disstate = request.getParameter("distributionstate");
				String phone1=request.getParameter("phone1");
				String phone2 = request.getParameter("phone2");
				String remarks = request.getParameter("remarks");
				String distime = request.getParameter("distributiontime");
				//String username = (String) request.getSession().getAttribute("username");
				
				
				
				
				
				//插入数据库部分
				//将所有获取的属性写入插入语句中去
//				String insert = "insert into sales(id, chinesename,englishname,sex,birthday,reservation,attend,messagefrom,marketman,"
//						+ "counselor,phonecounselor,distributionstate,distributiontime,username)values('"+finalserial+"','"+cname+"','"+ename+"','"+sex+"',"
//								+ "'"+birthday+"','"+reservaiton+"','"+attend+"','"+messagefrom+"','"+marketman+"','"+counselor+"','"+pcounselor+"','"+disstate+"',"
//										+ "'"+distime+"','"+username+"')";
				String update="update sales set chinesename='"+cname+"',englishname='"+ename+"',sex='"+sex+"',birthday='"+birthday+"',messagefrom='"+messagefrom+"',marketman='"+marketman+"',"
						+ "counselor='"+counselor+"',phonecounselor='"+pcounselor+"',distributionstate='"+disstate+"',distributiontime='"+distime+"',phone1='"+phone1+"',phone2='"+phone2+"',remarks='"+remarks+"' where id='"+id+"'";
				Jdbc j1 = null;
			
				try {
					j1= new Jdbc(update);
					
				} catch (ClassNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
					
					 request.getRequestDispatcher("showsuccess.jsp").forward(request, response);
	}

}
